﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Package;
using Microsoft.VisualStudio.TextManager.Interop;
using System.Drawing;

namespace FixtureHighlighter
{
    public class FixtureColorableItems : IList<IVsColorableItem>
    {
        List<IVsColorableItem> _items = new List<IVsColorableItem>();

        public TokenColor ErrorColor
        {
            get;
            set;
        }

        public FixtureColorableItems()
        {
            // the default colors
            CreateColor("Keyword", "Keyword", COLORINDEX.CI_BLUE, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Comment", "Comment", COLORINDEX.CI_DARKGREEN, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Identifier", "Identifier", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("String", "String", COLORINDEX.CI_MAROON, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Number", "Number", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Text", "Text", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK);
            CreateColor("Reference", "Reference", COLORINDEX.CI_PURPLE, COLORINDEX.CI_USERTEXT_BK);

            // extra colors
            ErrorColor = CreateColor("Error", "Error", COLORINDEX.CI_SYSPLAINTEXT_FG, COLORINDEX.CI_USERTEXT_BK, false, false);
        }

        public TokenColor CreateColor(string name, string displayName, COLORINDEX foreground, COLORINDEX background)
        {
            return CreateColor(name, displayName, foreground, Color.Empty, background, Color.Empty, false, false);
        }
        public TokenColor CreateColor(string name, string displayName, COLORINDEX foreground, COLORINDEX background, bool bold, bool strikethrough)
        {
            return CreateColor(name, displayName, foreground, Color.Empty, background, Color.Empty, bold, strikethrough);
        }
        public TokenColor CreateColor(string name, string displayName, COLORINDEX foreground, Color hiForeground, COLORINDEX background, Color hiBackground)
        {
            return CreateColor(name, displayName, foreground, hiForeground, background, hiBackground, false, false);
        }
        public TokenColor CreateColor(string name, string displayName, COLORINDEX foreground, Color hiForeground, COLORINDEX background, Color hiBackground, bool bold, bool strikethrough)
        {
            _items.Add(new FixtureColorableItem(name, displayName, foreground, hiForeground, background, hiBackground, bold, strikethrough));
            return (TokenColor)_items.Count;
        }

        #region IList<IVsColorableItem> Members

        public int IndexOf(IVsColorableItem item)
        {
            return _items.IndexOf(item);
        }

        public void Insert(int index, IVsColorableItem item)
        {
            _items.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            _items.RemoveAt(index);
        }

        public IVsColorableItem this[int index]
        {
            get
            {
                return _items[index];
            }
            set
            {
                _items[index] = value;
            }
        }

        #endregion

        #region ICollection<IVsColorableItem> Members

        public void Add(IVsColorableItem item)
        {
            _items.Add(item);
        }

        public void Clear()
        {
            _items.Clear();
        }

        public bool Contains(IVsColorableItem item)
        {
            return _items.Contains(item);
        }

        public void CopyTo(IVsColorableItem[] array, int arrayIndex)
        {
            _items.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get
            {
                return _items.Count;
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return false;
            }
        }

        public bool Remove(IVsColorableItem item)
        {
            return _items.Remove(item);
        }

        #endregion

        #region IEnumerable<IVsColorableItem> Members

        public IEnumerator<IVsColorableItem> GetEnumerator()
        {
            return _items.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        #endregion

    }
}
